package com.qire.common.concurrent;

/**
 * 一次运行线程包装器
 * @param <T>
 */
public class OnceRunWrapper<T> extends RunWrapper<T,OnceRunWrapper<T>> {

    public OnceRunWrapper() {
        super("OnceRunWrapper");
    }

    @Override
    protected Runnable buildWorker() {
        return new ExecuteWorker(worker);
    }

    private class ExecuteWorker extends Worker implements Runnable {

        public ExecuteWorker(Worker<T> worker) {
            super(worker, Scheduler.Sync);
        }

        @Override
        public void run() {
            accept(data);
        }
    }
}
